package comparisons

import (
	"JVM/Jvmgo/GoToJVM/instructions/base"
	"JVM/Jvmgo/GoToJVM/runtimeData"
)

/*
比较指令，这里比较 栈顶两个float类型
*/
type FCMPG struct {
	base.NoOperandsInstruction
}
type FCMPL struct {
	base.NoOperandsInstruction
}

func _fcmp(frame *runtimeData.Frame, gFlag bool) {
	stack := frame.OperandStack()
	val2 := stack.PopFloat()
	val1 := stack.PopFloat()
	if val1 > val2 {
		stack.PushInt(1)
	} else if val1 == val2 {
		stack.PushInt(0)
	} else if val1 < val2 {
		stack.PushInt(-1)
	} else if gFlag {
		stack.PushInt(1)
	} else {
		stack.PushInt(-1)
	}
}

func (self *FCMPG) Execute(frame *runtimeData.Frame) {
	_fcmp(frame, true)
}
func (self *FCMPL) Execute(frame *runtimeData.Frame) {
	_fcmp(frame, false)
}
